package com.tarena.lbs.common.passport.converter;


import com.tarena.lbs.common.passport.enums.Roles;
import com.tarena.lbs.common.passport.principle.UserPrinciple;
import com.tarena.lbs.pojo.passport.bo.AdminBO;
import com.tarena.lbs.pojo.passport.bo.UserBO;
import com.tarena.lbs.pojo.passport.dos.AdminDO;
import com.tarena.lbs.pojo.passport.dos.UserDO;
import com.tarena.lbs.pojo.passport.vo.LoginVO;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Component;

@Component
public class LoginConverter {
    public LoginVO userbo2loginvo(UserBO bo) {
        LoginVO vo = new LoginVO();
        BeanUtils.copyProperties(bo, vo);
        return vo;
    }

    public UserBO userdo2userbo(UserDO userDO) {
        if (userDO == null) {
            return null;
        }
        UserBO userBO = new UserBO();
        BeanUtils.copyProperties(userDO, userBO);
        return userBO;
    }

    public UserPrinciple userbo2principal(UserBO bo) {
        UserPrinciple userPrinciple = new UserPrinciple();
        BeanUtils.copyProperties(bo,userPrinciple);
        userPrinciple.setRole(Roles.USER);
        userPrinciple.setNickname(bo.getNickName());
        return userPrinciple;
    }

    public LoginVO adminbo2loginvo(AdminBO adminBO) {
        LoginVO vo = new LoginVO();
        BeanUtils.copyProperties(adminBO, vo);
        return vo;
    }

    public UserPrinciple adminbo2principal(AdminBO adminBO) {
        UserPrinciple userPrinciple = new UserPrinciple();
        BeanUtils.copyProperties(adminBO,userPrinciple);
        userPrinciple.setRole(adminBO.getAccountType()==0?Roles.ADMIN:Roles.SHOP);
        return userPrinciple;
    }

    public AdminBO admindo2adminbo(AdminDO adminDO) {
        if (adminDO == null) {
            return null;
        }
        AdminBO adminBO=new AdminBO();
        BeanUtils.copyProperties(adminDO, adminBO);
        return adminBO;
    }
}
